package com.yzy.mall.repository


import com.blankj.utilcode.util.LogUtils
import com.yzy.baselibrary.base.BaseLiveData
import com.yzy.baselibrary.base.BaseViewModel

class CardViewModel : BaseViewModel() {
//    private var page = 1
//    private var pageSize = 20
    private val ganRepository: CardRepository by lazy { CardRepository() }
    private val _bannerAndArticleResult: BaseLiveData<BaseUiModel<CardBean>> = BaseLiveData()
    val uiState: BaseLiveData<BaseUiModel<CardBean>> get() = _bannerAndArticleResult

    private val _registerResult: BaseLiveData<BaseUiModel<Any>> = BaseLiveData()
    val uiRegisterState: BaseLiveData<BaseUiModel<Any>> get() = _registerResult



//    private val _infoResult: BaseLiveData<BaseUiModel<InfoBean>> = BaseLiveData()
//    val uiInfoState: BaseLiveData<BaseUiModel<InfoBean>> get() = _infoResult


    fun getCard(str:String?) {
        emitArticleUiState(true)
        launchOnlyresult({ ganRepository.getCard(str?:"") }, {
            emitArticleUiState(false,it)
            LogUtils.e(it.limitedstatus)
        })
    }

//    fun iscard(str:String?) {
//        emitUiInfoState(true)
//        launchOnlyresult1({ ganRepository.iscard(str?:"") }, {
//            emitUiInfoState(false,it)
//        })
//    }

    fun wineMembers(idCard: String,  phoneNo: String,  userName: String, receivingAddress: String) {
        emitUiState(true)
        launchOnlyresult1({ ganRepository.wineMembers(idCard, phoneNo, userName,receivingAddress) }, {
            emitUiState(false,it.data)
        })
    }

    private fun emitArticleUiState(
        showLoading: Boolean = false,
        success: CardBean? = null
    ) {
        val uiModel = BaseUiModel(showLoading = showLoading, success = success)
        uiState.update(uiModel)
    }

    private fun emitUiState(
        showLoading: Boolean = false,
        success: Any? = null
    ) {
        val uiModel = BaseUiModel(showLoading = showLoading, success = success)
        _registerResult.update(uiModel)
    }

//    private fun emitUiInfoState(
//        showLoading: Boolean = false,
//        success: InfoBean? = null
//    ) {
//        val uiModel = BaseUiModel(showLoading = showLoading, success = success)
//        uiInfoState.update(uiModel)
//    }
}